package com.zhou.controller;

import com.zhou.dto.vip.VipDTO;
import com.zhou.result.R;
import com.zhou.service.VipService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContextException;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description : VIP等级
 * @Author : zyy
 * @Date: 2024/6/19  15:04
 */
@RequestMapping("/vip_level")
@RestController
@Slf4j
@Api(tags = "VIP等级")
public class VipController {
    @Resource
    private VipService vipService;

    /**
     * 购买VIP
     *
     * @param dto
     * @return
     */
    @PostMapping("/add")
    @Operation(summary = "购买VIP")
    private R add(@RequestBody VipDTO dto) {
        try {
            return R.success(vipService.add(dto));
        } catch (ApplicationContextException e) {
            return R.error(e.getMessage());
        }
    }

    /**
     * 分页查询VIP购买记录
     *
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    @Operation(summary = "分页查询VIP购买记录")
    private R list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pageSize) {
        return R.success(vipService.list(page, pageSize));
    }

    /**
     * 停用VIP
     */
    @PutMapping("/stop")
    @Operation(summary = "停用VIP")
    private R stop(@RequestParam String id) {
        try {
            return R.success(vipService.stop(id));
        } catch (ApplicationContextException e) {
            return R.error(e.getMessage());
        }
    }
}